/* ************************************************************************** */ 
/* Example of a syndication feed reader using the Project Rome API with       */ 
/* BSF4ooRexx                                                                 */ 
/* current version of Rome: rome1.0.jar            https://rome.dev.java.net/ */ 
/* You need to implement this API plus the JDOM API                           */ 
/* jdom.jar  ,   you can find this at               https://jdom.org/        ; */ 
/*                                                                            */ 
/* This example retrieves several feeds from a URI and aggregates them        */ 
/* to a single one                                                            */                    
/* created by Martin Stoppacher     date:   26.12.2009    (c) 2009            */ 
/* license:ÊÊÊÊLGPL 3.0ÊÊÊÊÊÊÊused versions: Java 1.6, ooRexx 4.0, Bsf4ooRexx */ 
/*             (Lesser Gnu Public License version 3.0),                       */ 
/*             cf. <http://www.gnu.org/licenses/lgpl.html>                    */ 
/* ************************************************************************** */ 
 
say hello this aggregates syndfeeds 
                        
say type in the urls _ to end type in _ end _ 
/*          this creates an array of feed urls which will later be aggregated */ 
tmpColl = .array ~new 
= 0 
do until url = "end" 
PARSE PULL url 
if url = "end" 
then 
say over 
else 
do
= i + 1 
say i  
tmpColl[i] = url 
end 
end 

say "your urls are :" 
SAY tmpColl~string || ":" 
DO item OVER tmpColl 
SAY "[" || item || "]" 
END 

/*                                                        optional type input */ 
--pull typet
typet="rss_2.0" 
fileName = "test4_aggregated_feed" typet 

call Syssleep 1 
say 'Your crated feed starts hear :' 

feed=.bsf~new("com.sun.syndication.feed.synd.SyndFeedImpl") 
/*      using syndfeedImpl to creat a feed using the independent object model */ 
feed~setFeedType(typet) 
/*                                                 sets the type of this feed */ 

feed~setTitle("Aggregated Feed") 
feed~setDescription("Anonymous Aggregated Feed") 
feed~setAuthor("Martin Stoppacher") 
feed~setLink("http://martinstoppacher.com") 
/*             create some entries for the feed by using the SyndFeed methods */ 
 
/*                       creates a Java array list for the entries of the feed*/ 
entries =.bsf~new("java.util.ArrayList") 
/*                                 sets the Java array as entries of the feed */ 
feed~setEntries(entries) 

/* this uses the URL array to retrieve the entries fro the feeds              */ 
/* and add them to the entries array                                          */ 
do y=to 1 by -1 
feedUrl=.bsf~new("java.net.URL",tmpColl~at(i)) 
input=.bsf~new("com.sun.syndication.io.SyndFeedInput") 
xmlr=.bsf~new("com.sun.syndication.io.XmlReader", feedUrl) 
infeed=input~build(xmlr) 
entries~addAll(infeed~getEntries()) 
end 

/*                                             output of the aggregated feeds */  
output=.bsf~new("com.sun.syndication.io.SyndFeedOutput") 
say output~outputString(feed,1)     /* usage of pretty print(0 yes or 1 no)   */ 

/*                                                                writer part */  
writer=.bsf~new("java.io.FileWriter",fileName) 
output~output(feed,writer) 
writer~close() 


PP : RETURN "[" || ARG(1)|| "]" 
::requires BSF.cls